package com.example.myblog.controller;

import com.example.myblog.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.HashMap;

@Controller
public class ArchiveShowController {

    @Autowired
    private BlogService blogService;
    @GetMapping("/archives")
    public String archives(Model model){
        HashMap<String,Object> map = new HashMap<>();
        map.put("2020",blogService.listByYear("2020"));
        map.put("2021",blogService.listByYear("2021"));
        map.put("2022",blogService.listByYear("2022"));
        model.addAttribute("archiveMap",map);
        model.addAttribute("blogCount", blogService.countBlog());
        return "archives";
    }

}
